<!-- 待取走详情 -->
<template>
	<ListLayout>
		<Tips :leftText="'派单时间:'+SendRepairInfo.createTime || '-'" :rightText="stateParams.text" :color="stateParams.color[stateParams.state]"> </Tips>
		<!-- 取件 -->
		<SendRapirProcess>
			<template #top>
				<SendRapirInfo :info="PickUpInfo" text="取"></SendRapirInfo>
			</template>
			<template #bottom>
				<SendRapirInfo :info="CollectInfo" color="green" text="收"></SendRapirInfo>
			</template>
		</SendRapirProcess>
		<!-- 设备信息 -->
		<DeviceCard :sendRepairInfo="SendRepairInfo"></DeviceCard>
		<!-- 故障信息 -->
		<FaultCard :sendRepairInfo="SendRepairInfo"></FaultCard>

		<template v-if="SendRepairInfo.currState !='wait_dept_takeaway'">
			<!-- 其他信息 -->
			<OtherCard :invoiceInfo="InvoiceInfo"></OtherCard>
		</template>


		<template #footer>
			<view class="footer">
				<ButtonBetween :rightPlain="false" @rightClick="rightClick" @leftClick="leftClick">
					<template #left>
						暂停
					</template>
					<template #right>
						取走
					</template>
				</ButtonBetween>
			</view>
		</template>
	</ListLayout>
</template>

<script>
	import Tips from '@/components/tips/orderTips.vue'
	import ListLayout from '@/components/layout/listLayout.vue'

	import SendRapirProcess from '@/components/card/sendRapirProcess.vue'
	import SendRapirInfo from '@/components/info/sendRapir.vue'


	import DeviceCard from '@/components/card/sendRepair/factory/info/device.vue'
	import FaultCard from '@/components/card/sendRepair/factory/info/fault.vue'

	import OtherCard from '@/components/card/sendRepair/factory/info/return-other.vue'
	import ButtonBetween from '@/components/buttonGroup/optionButtonGroup.vue'
	import ReapirApi from '@/apis/repair.js'
	import { factoryState } from '@/sendRepair/factory/state.js'
	import SendRepairRouterConfig from '@/sendRepair/routerConfig.js'
	export default {
		components: {
			Tips,
			ListLayout,
			SendRapirProcess,
			SendRapirInfo,
			DeviceCard,
			FaultCard,
			OtherCard,
			ButtonBetween
		},
		computed: {
			InvoiceInfo() {
				let { finishRepairResultVo } = this.data
				return finishRepairResultVo || {}
			},
			SendRepairInfo() {
				let {
					repairInfo
				} = this.data
				return repairInfo || {}
			},
			// 取件信息
			PickUpInfo() {
				let {
					takeAwayInfoVo
				} = this.data
				return {
					addr: takeAwayInfoVo?.takePlace || '',
					department: takeAwayInfoVo?.takeDeptToName || '',
					user: takeAwayInfoVo?.takeUser || '',
					phone: takeAwayInfoVo?.phone || ''
				}
			},
			//收件信息
			CollectInfo() {
				let {
					takeAwayInfoVo
				} = this.data
				return {
					addr: takeAwayInfoVo?.receivePlace || '',
					department: takeAwayInfoVo?.receiveDeptToName || '',
					user: takeAwayInfoVo?.receiveUserToName || "",
					phone: takeAwayInfoVo?.receivePhone || ''
				}
			},

		},
		data() {
			return {
				data: {},
				stateParams: {
					color: factoryState.colors,
					text: '',
					state: ''
				},
				routerParams: {
					id: ''
				}
			}
		},
		async onLoad(query) {
			const {
				state,
				currStateToName,
				id
			} = query
			this.$set(this.stateParams, 'text', currStateToName)
			this.$set(this.stateParams, 'state', state)
			this.$set(this.routerParams, 'id', id)

			console.log(query, 'onLoad---query')
			let res = await ReapirApi.common.getDetail(id)
			if (res.code === 0) {
				this.data = res.body || {}

			}

		},
		methods: {
			async leftClick() {
				await ReapirApi.common.pause(this.routerParams.id)
				wx.showToast({
					title: '暂停成功',
					icon: 'success',
					complete() {
						wx.redirectTo({
							url: SendRepairRouterConfig.Department.Index
						})
					}
				})
			},
			rightClick() {
				wx.navigateTo({
					url: `${SendRepairRouterConfig.Department.PickUpConfirm}?id=${this.routerParams.id}&process_state=${this.data.repairInfo.currState}`
				})
			}
		},

	}
</script>

<style lang="scss" scoped>
	.footer {
		padding: 20rpx 20rpx 0 20rpx;
	}
</style>
